﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CNotebook
{
    public class AcctDeterminationManager:ConnectionManager
    {
        public DataTable GetAccountDetermination()
        {
            SqlCommand oCommand = new SqlCommand();
            SqlDataAdapter oAdapter = new SqlDataAdapter();
            DataTable dt = new DataTable();

            oCommand.Connection = this.Connection;
            oCommand.CommandText = "SELECT * FROM ACCOUNTDETERMINATION";

            oAdapter.SelectCommand = oCommand;
            oAdapter.Fill(dt);

            return dt;
            
        }

        public SqlException UpdateDetermination(DataTable dt)
        {
            SqlCommand oCommand = new SqlCommand();

            try
            {
                foreach (DataRow oRow in dt.Rows)
                {
                    oCommand = new SqlCommand();

                    oCommand.Connection = this.Connection;
                    oCommand.CommandText = "UPDATE ACCOUNTDETERMINATION SET AcctCode=@AcctCode, AcctName=@AcctName WHERE ObjectID=@ObjectID";
                    oCommand.Parameters.Add(new SqlParameter("@AcctCode", oRow["AcctCode"].ToString()));
                    oCommand.Parameters.Add(new SqlParameter("@AcctName", oRow["AcctName"].ToString()));
                    oCommand.Parameters.Add(new SqlParameter("@ObjectID", oRow["ObjectID"].ToString()));
                    oCommand.ExecuteNonQuery();
                }

                return null;
            }
            catch (SqlException ex)
            {
                return ex;
            }
            finally
            {
                oCommand.Dispose();
            }
        }
    }
}
